Refactor duplicated code patterns into shared utilities (scripts/util.js)#677
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Refactor duplicated code patterns into shared utilities (scripts/util.js)#677devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Extract 10 shared functions/constants into scripts/util.js: - checkElem, encodeToBase64, decodeFromBase64: DOM/encoding helpers - languages: language-to-extension map (was in leetcode.js) - convertToSlug: string slugification (was in leetcode.js) - getSHA, createDefaultStats: chrome.storage stat helpers - githubRequest: authenticated GitHub API XHR wrapper - setDisplayMode, displayStats: UI state helpers Refactored across leetcode.js, gfg.js, popup.js, welcome.js. Net reduction of 66 lint errors (202 -> 131, all remaining pre-existing). Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts 10 duplicated code patterns from across the codebase into a new
scripts/util.jsshared utility file, reducing copy-paste duplication and lowering lint errors from 161 → 95 (net -66 errors).What moved to
scripts/util.js:encodeToBase64(str)/decodeFromBase64(str)btoa(unescape(encodeURIComponent(str)))and reversegithubRequest(method, url, token, data, cb)Authorization+AcceptheadersgetSHA(stats, filePath)checkElem(elem)elem && elem.length > 0— now available to all content scriptslanguagesconvertToSlug(string)createDefaultStats(){ solved: 0, easy: 0, medium: 0, hard: 0, sha: {} }setDisplayMode(mode)hook_mode/commit_modedisplaydisplayStats(stats)Wiring:
manifest.json:scripts/util.jsadded before content scriptspopup.html/welcome.html:<script src="scripts/util.js">added before page scripts/* global ... */directives added to consumer files for ESLintLink to Devin session: https://app.devin.ai/sessions/14c9a3a6edd84c35a8f66db154eaa4a3
Requested by: @QasimWani